class_name HStateManage
extends Node

@export var InitNode:HStateNode

var _current_node:HStateNode
var _state_node_list:Array[HStateNode] = []
var _state_node_dict:Dictionary = {}

func set_up():
	pass

func _physics_process(delta: float) -> void:
	if is_instance_valid(InitNode):
		_current_node.update(delta)

func _ready() -> void:
	_collect_state_node_list()
	set_up()
	for i in _state_node_list:
		i.set_up()
	if is_instance_valid(InitNode):
		_current_node = InitNode
	elif _state_node_list.size()>0:
		_current_node = _state_node_list[0]
	if is_instance_valid(InitNode):
		_current_node.enter()

func _collect_state_node_list():
	for i in get_children():
		if i is not HStateNode:
			continue
		i = i as HStateNode
		i._manager = self
		if not i.StateName.is_empty():
			_state_node_dict[i.StateName] = i
		_state_node_list.append(i)
